package anbook.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import anbook.dao.controller.MemberController;
import anbook.dto.Friend;
import anbook.dto.Friends_request;

/**
 * Servlet implementation class FriendRequestServlet
 */

@WebServlet("/FriendRequest")
public class FriendRequestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FriendRequestServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.sendRedirect("/BookProject/");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf8"); 
		
		HttpSession session = request.getSession();
		
		if (session.getAttribute("email") != null){
			String friend_email = request.getParameter("friend_email");
			if (friend_email != null){
				Friends_request f_request = new Friends_request();
				
				f_request.setRequest_email(session.getAttribute("email").toString());
				f_request.setFriend_email(friend_email);
				
				MemberController mc = new MemberController();
				
				mc.friendRequest(f_request);
			}
		}
		
		response.sendRedirect("/BookProject/");
	}

}
